package com.ruoyi.book.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.ruoyi.book.domain.BookCommission;
import org.springframework.security.access.prepost.PreAuthorize; // 保留引用
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.book.domain.BookCommissionUsers;
import com.ruoyi.book.service.IBookCommissionUsersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图书委托用户Controller
 *
 * @author hd
 * @date 2025-03-31
 */
@RestController
@RequestMapping("/book/users")
@Api(tags = "图书委托用户管理")
public class BookCommissionUsersController extends BaseController {
    @Autowired(required = false)
    private IBookCommissionUsersService bookCommissionUsersService;

    /**
     * 查询图书委托用户列表
     */
    @ApiOperation("查询图书委托用户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookCommissionUsers", value = "查询条件对象（如用户ID、名称等）", required = false, paramType = "query", dataType = "BookCommissionUsers")
    })
    // 注释权限控制
    // @PreAuthorize("@ss.hasPermi('book:users:list')")
    @GetMapping("/list")
    public TableDataInfo list(BookCommissionUsers bookCommissionUsers,Integer pageNum,Integer pageSize)
    {
        if(pageNum!=null&&pageSize!=null){
            PageHelper.startPage(pageNum,pageSize);
        }else{
            startPage();
        }
        List<BookCommissionUsers> list = bookCommissionUsersService.selectBookCommissionUsersList(bookCommissionUsers);
        return getDataTable(list);
    }

    /**
     * 导出图书委托用户列表
     */
    @ApiOperation("导出图书委托用户列表为Excel文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookCommissionUsers", value = "查询条件对象（如用户ID、名称等）", required = false, paramType = "query", dataType = "BookCommissionUsers")
    })
    // 注释权限控制
    // @PreAuthorize("@ss.hasPermi('book:users:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BookCommissionUsers bookCommissionUsers) {
        List<BookCommissionUsers> list = bookCommissionUsersService.selectBookCommissionUsersList(bookCommissionUsers);
        ExcelUtil<BookCommissionUsers> util = new ExcelUtil<>(BookCommissionUsers.class);
        util.exportExcel(response, list, "图书委托用户数据");
    }

    /**
     * 获取图书委托用户详细信息
     */
    @ApiOperation("获取图书委托用户详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "path", dataType = "Long", example = "123")
    })
    // 注释权限控制
    // @PreAuthorize("@ss.hasPermi('book:users:query')")
    @GetMapping("/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return success(bookCommissionUsersService.selectBookCommissionUsersByUserId(userId));
    }

    /**
     * 新增图书委托用户
     */
    @ApiOperation("新增图书委托用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookCommissionUsers", value = "图书委托用户信息", required = true, paramType = "body", dataType = "BookCommissionUsers")
    })
    @Log(title = "图书委托用户", businessType = BusinessType.INSERT)
    // 注释权限控制
    // @PreAuthorize("@ss.hasPermi('book:users:add')")
    @PostMapping
    public AjaxResult add(@RequestBody BookCommissionUsers bookCommissionUsers) {
        return toAjax(bookCommissionUsersService.insertBookCommissionUsers(bookCommissionUsers));
    }

    /**
     * 修改图书委托用户
     */
    @ApiOperation("修改图书委托用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bookCommissionUsers", value = "图书委托用户信息", required = true, paramType = "body", dataType = "BookCommissionUsers")
    })
    @Log(title = "图书委托用户", businessType = BusinessType.UPDATE)
    // 注释权限控制
    // @PreAuthorize("@ss.hasPermi('book:users:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody BookCommissionUsers bookCommissionUsers) {
        return toAjax(bookCommissionUsersService.updateBookCommissionUsers(bookCommissionUsers));
    }

    /**
     * 删除图书委托用户
     */
    @ApiOperation("删除图书委托用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userIds", value = "用户ID数组（如：1,2,3）", required = true, paramType = "path", dataType = "Long[]", example = "1,2,3")
    })
    @Log(title = "图书委托用户", businessType = BusinessType.DELETE)
    // 注释权限控制
    // @PreAuthorize("@ss.hasPermi('book:users:remove')")
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(bookCommissionUsersService.deleteBookCommissionUsersByUserIds(userIds));
    }
}